//
//  AnJiaMarkBMKAnnotationView.m
//  flutter_bmfbase
//
//  Created by VM on 2021/1/21.
//

#import "AnJiaMarkBMKAnnotationView.h"
#import "GlobalConfig.h"
#import "UIView+Frame.h"

@implementation AnJiaMarkBMKAnnotationView

- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        self.frame = CGRectZero;
        self.clipsToBounds = YES;
        self.iconView.clipsToBounds = YES;
        [self initSubViews];
        [self initTap];
    }
    return self;
}

- (void)showAnimation {
    [UIView animateWithDuration:0.3 animations:^{
        self.iconView.transform = CGAffineTransformIdentity;
    }];
}


- (void)initSubViews{
    [self addSubview:self.iconView];
    [self.iconView addSubview:self.titleLab];
    [self.iconView addSubview:self.leftIconView];
    self.iconView.transform = CGAffineTransformMakeScale(0,0);
    [self showAnimation];
}

- (void)initTap {
    self.userInteractionEnabled = YES;
}

- (UIImageView *)iconView{
    if (!_iconView){
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}

- (UIImageView *)leftIconView {
    if (!_leftIconView) {
        _leftIconView = [[UIImageView alloc] init];
    }
    return _leftIconView;
}


- (UILabel *)titleLab{
    if (!_titleLab){
        _titleLab = [[UILabel alloc] init];
        _titleLab.textAlignment = NSTextAlignmentLeft;
        _titleLab.font = [UIFont boldSystemFontOfSize:11];
        _titleLab.numberOfLines = 0;
    }
    return _titleLab;
}

- (void)setUpdateSmallProint:(NSString *)titleText isSelect:(BOOL)isSelect iconImageName:(UIImage *)iconImageName {
    NSLog(@"-----%@",iconImageName);
    self.layer.cornerRadius = 0;
    self.iconView.layer.cornerRadius = 0;
    self.titleLab.numberOfLines = 2;
    self.iconView.backgroundColor = UIColor.clearColor;
    UIImage * nonIcon = [UIImage imageNamed:@"maphome_map_tag_none"];
    UIImage * selectIcon = [UIImage imageNamed:@"maphome_map_tag_select"];
    self.titleLab.textColor  = [UIColor whiteColor];
    self.iconView.image = isSelect ? selectIcon : nonIcon;
    [self.leftIconView setImage:iconImageName];
    self.titleLab.text = titleText;
}

- (void)setSmallProint:(NSString *)titleText isSelect:(BOOL)isSelect iconImageName:(UIImage *)iconImageName {
    NSLog(@"-----%@",iconImageName);
    self.layer.cornerRadius = 0;
    self.iconView.layer.cornerRadius = 0;
    self.titleLab.numberOfLines = 2;
    self.iconView.backgroundColor = UIColor.clearColor;
    UIImage * nonIcon = [UIImage imageNamed:@"maphome_map_tag_none"];
    UIImage * selectIcon = [UIImage imageNamed:@"maphome_map_tag_select"];
    CGRect viewFrame = isSelect ? CGRectMake(0, 0, selectIcon.size.width, selectIcon.size.height) : CGRectMake(0, 0, nonIcon.size.width, nonIcon.size.height);
    self.frame = viewFrame;
    self.iconView.frame = viewFrame;
    self.leftIconView.frame = CGRectMake(15, 0.5*(viewFrame.size.height - 12), 12, 12);
    self.titleLab.textColor  = [UIColor whiteColor];
    
    self.iconView.image = isSelect ? selectIcon : nonIcon;
    [self.leftIconView setImage:iconImageName];
    self.titleLab.text = titleText;
    self.titleLab.frame = CGRectMake(self.leftIconView.right + 5, 0, viewFrame.size.width -30, viewFrame.size.height);
//    [self.titleLab sizeToFit];
//    self.titleLab.centerY = self.centerY;
//    self.titleLab.left = self.leftIconView.right + 5;
    
//    self.iconView.width = self.titleLab.right + 15;
//    self.width = self.iconView.width;
//    self.titleLab.frame = CGRectMake(self.leftIconView.right + 5, 0, self.width -(self.leftIconView.right + 10), self.height);
    [self showAnimation];
}

@end
